package com.amit.servlet;

import java.util.ArrayList;


import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebListener
public class MySessionListener implements HttpSessionListener
{
	
	ServletContext context=null;
	HttpSession session=null;
	
	
	@Override
	public void sessionCreated(HttpSessionEvent hse) 
	{
	
		session=hse.getSession();
		context=session.getServletContext();
		
		int tv=Integer.parseInt(context.getAttribute("TV").toString());
		tv++;
		
		int co=Integer.parseInt(context.getAttribute("CO").toString());
		co++;
		
		context.setAttribute("TV", new Integer(tv));
		context.setAttribute("CO", new Integer(co));
		
	}
	
	@Override
	public void sessionDestroyed(HttpSessionEvent hse) {
		
		System.out.println("session Destroyed");
		
		session=hse.getSession();
		context=session.getServletContext();
		int co=Integer.parseInt(context.getAttribute("CO").toString());
		co--;
		context.setAttribute("CO", new Integer(co));
		
	}
		
		
	

}
